<?php
// Yii::setPathOfAlias('Imagine',Yii::getPathOfAlias('application.vendors.Imagine'));

class StartWebsocketServerCommand extends CConsoleCommand
{
    public function run($args)
    {
/*        $server = new \WebSocket\Server('127.0.0.1', 8000, false); // host,port,ssl

        // server settings:
        $server->setCheckOrigin(true);
        $server->setAllowedOrigin('websockets-test.local');
        $server->setMaxClients(100);
        $server->setMaxConnectionsPerIp(20);
        $server->setMaxRequestsPerMinute(1000);

        $server->registerApplication('demo', \WebSocket\Application\DemoApplication::getInstance());
        $server->run();*/
        ini_set('display_errors', 1);
        error_reporting(E_ALL);

        // require(__DIR__ . '/lib/SplClassLoader.php');
        // Yii::import('ext.php-websocket.server.lib.SplClassLoader');

        // $classLoader = new SplClassLoader('WebSocket', Yii::getPathOfAlias('ext.php-websocket.server.lib'));
        // $classLoader->register();

        // $server = new \WebSocket\Server('127.0.0.1', 8000, false);
        $server = new WebsocketServer('127.0.0.1', 8000, false);

        // server settings:
        $server->setMaxClients(100);
        $server->setCheckOrigin(false);
        $server->setAllowedOrigin('websockets-test.local');
        $server->setMaxConnectionsPerIp(100);
        $server->setMaxRequestsPerMinute(2000);

        // Hint: Status application should not be removed as it displays usefull server informations:
        $server->registerApplication('status', \WebSocket\Application\StatusApplication::getInstance());
        $server->registerApplication('demo', \WebSocket\Application\DemoApplication::getInstance());

        $server->run();
    }
}
